import json
import logging
import random
import re
import subprocess
import time
from datetime import datetime, timedelta
import os
from ascript.android.screen import FindColors
from ascript.android.screen import FindImages
# 导入上下文环境包,方便导入图片地址
from ascript.android.system import R

from ascript.android import action

import websocket
from apscheduler.schedulers.background import BackgroundScheduler
from airscript.ui.dialog import toast
from ascript.android.node import Selector
# 导入系统资源模块
from ascript.android.system import R
# 导入动作模块
from ascript.android import action
# 导入节点检索模块
from ascript.android import node
# 导入图色检索模块
from ascript.android import screen

from airscript.system import Channel
import requests
from websocket import create_connection
from pytz import timezone
import pickle

from .ai_aip import get_btn, ai_btn_mate

from .user_message_list import add_assistant_start

# 从第一个文件中导入 logger
# from .__init__ import logger
#



# 配置日志记录以捕获调度器的错误
logging.basicConfig(level=logging.INFO, force=True)
logger = logging.getLogger(__name__)

logger.info("程序开始运行 log")






def some_function():
    # 使用 logger 记录错误或其他日志
    logger.error("This is an error log from the second module.")


def wealth_value_detection():
    # 执行获取财富等级的操作
    Selector().id("com.tanyu.me:id/chat_avator").click().find()

    time.sleep(1)

    wealthlevel = Selector().id("com.tanyu.me:id/wealthlevel").find().text
    Selector().id("com.tanyu.me:id/login_back").click().find()
    logger.info(f"他的财富数据为: {wealthlevel}")
    wealthlevel_num = 0
    # 获取财富等级数值
    # 将字符串按照指定的分隔符切割，获取分隔符后的部分
    parts = wealthlevel.split("财富值LV")
    if len(parts) > 1:
        wealthlevel_num = int(parts[1])
    logger.info(f"他的财富等级为: {wealthlevel_num}")

    time.sleep(2)

    if wealthlevel_num < 10:
        return False
    else:
        return True


def user_message_get(message_num):
    message = []

    # 获取消息组件最后一条消息
    # 获取 所有的消息组件，获取最后一条消息内容返回给服务器

    all = Selector().id("com.qieyu.bottle:id/msg_content_fl").find_all()

    if not all:
        logger.info("找不到all跳出")
        return None

    # logger.info(f"all为: {all}")

    # 获取列表最后一项内容
    message_list = all[-message_num:]

    for item in message_list:
        message.append(item.text)

    logger.info(f"获取到消息: {message}")

    user_message = ""

    for item in message:
        user_message = user_message + item + "，"

    return user_message


def get_device_id():
    # 获取系统根目录
    current_file_path = os.path.abspath(__file__)

    # 获取根目录下的所有文件和文件夹
    items_in_root = os.path.dirname(current_file_path)

    # 指定你要查找的目录路径
    specified_directory = items_in_root  # 请替换为你的实际路径

    # 获取指定目录下的所有文件和文件夹
    items_in_directory = os.listdir(specified_directory)

    logger.info(items_in_directory)

    # 查找文件夹名称中包含 "device_id" 的文件夹
    folders_with_device_id = [item for item in items_in_directory if
                              os.path.isdir(os.path.join(specified_directory, item)) and "device_id" in item]

    # 打印结果
    if folders_with_device_id:
        # logger.info("找到包含 'device_id' 的文件夹：")
        for folder in folders_with_device_id:
            # logger.info(folder)
            a = 1

            return folder
    else:
        logger.info("没有找到包含 'device_id' 的文件夹。")

        # 指定你想要创建文件夹的路径
        specified_directory = items_in_root  # 请替换为你想要的路径

        # url = "http://127.0.0.1:5000/get_device_id"
        url = "http://103.149.200.228:8081/get_device_id"
        response = requests.post(url)
        logger.info(response.text)

        device_id = "device_id" + response.text

        # 创建一个名为 "device_id" 的文件夹
        device_id_folder_path = os.path.join(specified_directory, device_id)

        try:
            # 使用 os.makedirs 创建文件夹
            os.makedirs(device_id_folder_path, exist_ok=True)  # exist_ok=True 表示如果文件夹已存在，不会抛出异常
            logger.info(f"成功创建文件夹: {device_id_folder_path}")

            return device_id
        except Exception as e:
            logger.info(f"创建文件夹失败: {e}")


def first_chat_processing(message_num):
    # 财富值判断
    if not wealth_value_detection():
        # 退出聊天界面
        Selector().id("com.tanyu.me:id/title_back").click().find()
        time.sleep(1)
        return

    # 添加开场白
    # 获取起始瓶子内容
    if user_message_get(message_num):
        user_message = user_message_get(message_num)
    else:
        logger.info("找不到user_message跳出")
        return
    start_maeeage = ai_btn_mate(user_message)

    # 插入内容到服务器消息列表
    if not Selector().id("com.tanyu.me:id/chat_name").find():
        logger.info("找不到chat_name跳出")
        return
    user = Selector().id("com.tanyu.me:id/chat_name").find().text

    add_assistant_start(user, get_device_id(), start_maeeage)

    logger.info(f"add_assistant_start参数 user：{user} device_id:{get_device_id()}   start_maeeage:{start_maeeage}  ")


# 函数名：聊天界面判断
# 功能：判断当前界面是否为聊天界面
def chat_interface_judgment():
    if Selector().id("com.tanyu.me:id/chat_gengduo").find():
        return True


# 退出聊天界面
def exit_chat_interface():

    path = R.res("/img/come_back.png")  # 这里替换为你的图片地址
    res = FindImages.find(path)
    if res:
        print("中心坐标:", res["center_x"], res["center_y"])
        print("相似度:", res["confidence"])
        print("在屏幕中的范围:", res["rect"])

    action.click(res["center_x"], res["center_y"], 20)


def message_num_get():
    # 获取有几条消息，决定等取几个消息
    message_num = int(Selector().id("com.qieyu.bottle:id/conversation_unread").find().text)
    return message_num

# AI请求体封装
def encapsulate_ai_request_body(message_num,userName):
    device_id = get_device_id()

    if user_message_get(message_num):
        user_message = user_message_get(message_num)
    else:
        logger.info("找不到user_message跳出")
        return False


    data = {
        'device_id': device_id,
        'user': userName,
        'message': user_message,
        'role': "user",
    }

    return data


# 点击进入聊天界面
def click_enter_chat_interface():
    print("点击进入聊天界面")

    find2 = Selector().id("com.qieyu.bottle:id/conversation_unread").parent().click().find()

    if not find2:
        logger.info("找不到find2跳出")

    try:
        if not find2.find(Selector().child(2)):
            logger.info("找不到child(2)跳出")
    # 执行操作
    except TypeError as e:
        logger.info(f"发生了一个错误: {e}")
        logger.info("可能是因为 find_all 返回了 None，无法迭代。")


    Selector().id("com.qieyu.bottle:id/conversation_unread").parent().click().find()


# 截屏指定区域
def capture_specific_area(rect, file_name):

    from ascript.android import screen
    # bitmap = screen.capture(191, 990, 491, 1109)

    bitmap = screen.capture(rect[0], rect[1], rect[2], rect[3])

    # print(bitmap)

    # 将屏幕截图存储在SD卡下的1.png中
    from ascript.android import screen
    from ascript.android.system import R

    # 获取当前脚本的文件路径
    current_file_path = os.path.abspath(__file__)

    # 获取当前脚本所在的文件夹路径
    current_directory = os.path.dirname(current_file_path)

    current_directory = current_directory.replace("/storage/emulated/0", "", 1)

    # print(current_directory)

    screen.bitmap_to_file(R.sd(current_directory + r"/img2/" + file_name + ".png"), bitmap=bitmap)
    # screen.bitmap_to_file(R.sd(current_directory + r"/9.png"))

    print("截图成功")


def get_all_top_right_coordinates():

    screenshot_coordinates = [8, 116, 520, 814]

    point = FindColors.find('0,0,#F9E083|1,0,#F9E083|2,0,#F9E083|3,0,#F9E083|4,0,#F9E083|5,0,#F6E7B0|0,1,#F9E083|1,1,#F9E083|2,1,#F9E083|3,1,#F9E083|4,1,#F9E083|5,1,#F4EED9|0,2,#F9E083|1,2,#F9E083|2,2,#F9E083|3,2,#F9E083|4,2,#F6E7B0|5,2,#F2F2F2|0,3,#F9E083|1,3,#F9E083|2,3,#F9E083|3,3,#F7E5A2|4,3,#F2F2F2|5,3,#F2F2F2|0,4,#F9E083|1,4,#F9E083|2,4,#F6E7B0|3,4,#F2F2F2|4,4,#F2F2F2|5,4,#F2F2F2|0,5,#F6E7B0|1,5,#F4EED9|2,5,#F2F2F2|3,5,#F2F2F2|4,5,#F2F2F2|5,5,#F2F2F2', rect=screenshot_coordinates)

    if point:
        # 打印 x坐标 和 y坐标
        # print(point.x, point.y)

        print(f"get_top_left_coordinates point ：{point.x, point.y}")

        if point.x == 191:
            # print(f"get_top_left_coordinates point ：{point.x, point.y}")

            return (point.x, point.y)



    all_top_right_coordinates_list = []

    while True:

        if screenshot_coordinates[1] > 814:
            break

        path = R.res("/img/right.png")  # 这里替换为你的图片地址

        res = FindImages.find(path, rect = screenshot_coordinates)

        if res:
            print("中心坐标:", res["center_x"], res["center_y"])
            print("相似度:", res["confidence"])
            print("在屏幕中的范围:", res["rect"])

            if res["confidence"] > 0.99:
                print("找到匹配的范围:", res["rect"])
                all_top_right_coordinates_list.append(res["rect"])


                screenshot_coordinates = [res["rect"][0],res["rect"][1]+35,520,814]

            else:
                break

    return all_top_right_coordinates_list


def get_bottom_right_coordinates(top_right_coordinates, screenshot_coordinates):

    screenshot_coordinates = [top_right_coordinates[0], top_right_coordinates[1], screenshot_coordinates[2], screenshot_coordinates[3]]

    # screenshot_coordinates = [8, 116, 520, 814]

    point = FindColors.find(
        '0,0,#F9E083|1,0,#F9E083|2,0,#F9E083|3,0,#F9E083|4,0,#F9E083|5,0,#F6E7B0|0,1,#F9E083|1,1,#F9E083|2,1,#F9E083|3,1,#F9E083|4,1,#F9E083|5,1,#F4EED9|0,2,#F9E083|1,2,#F9E083|2,2,#F9E083|3,2,#F9E083|4,2,#F6E7B0|5,2,#F2F2F2|0,3,#F9E083|1,3,#F9E083|2,3,#F9E083|3,3,#F7E5A2|4,3,#F2F2F2|5,3,#F2F2F2|0,4,#F9E083|1,4,#F9E083|2,4,#F6E7B0|3,4,#F2F2F2|4,4,#F2F2F2|5,4,#F2F2F2|0,5,#F6E7B0|1,5,#F4EED9|2,5,#F2F2F2|3,5,#F2F2F2|4,5,#F2F2F2|5,5,#F2F2F2', rect=screenshot_coordinates)

    # 320pd
    point = FindColors.find(
            '0,0,#F9E083|1,0,#F9E083|2,0,#F9E083|3,0,#F9E083|4,0,#F9E083|5,0,#F7E6A5|0,1,#F9E083|1,1,#F9E083|2,1,#F9E083|3,1,#F9E083|4,1,#F9E186|5,1,#F3F0E4|0,2,#F9E083|1,2,#F9E083|2,2,#F9E083|3,2,#F9E083|4,2,#F4ECCC|5,2,#F1F1F1|0,3,#F9E083|1,3,#F9E083|2,3,#F9E083|3,3,#F5E9BA|4,3,#F1F1F1|5,3,#F1F1F1|0,4,#F9E083|1,4,#F8E087|2,4,#F4EBCA|3,4,#F1F1F1|4,4,#F1F1F1|5,4,#F1F1F1|0,5,#F6E7AC|1,5,#F3F0E4|2,5,#F1F1F1|3,5,#F1F1F1|4,5,#F1F1F1|5,5,#F1F1F1', rect=screenshot_coordinates)



    if point:
        # 打印 x坐标 和 y坐标
        # print(point.x, point.y)

        print(f"get_top_left_coordinates point ：{point.x, point.y}")

        return (point.x, point.y)




# 获取左上角坐标
def get_top_left_coordinates(screenshot_coordinates):
    print(f"get_top_left_coordinates screenshot_coordinates ：{screenshot_coordinates}")

    # ffffff
    # 查找一个满足颜色特征的点
    # 导包

    point = FindColors.find('0,0,#F2F2F2|1,0,#F2F2F2|2,0,#F2F2F2|3,0,#F2F2F2|4,0,#F4EED9|5,0,#F6E7B0|6,0,#F8E393|0,1,#F2F2F2|1,1,#F2F2F2|2,1,#F2F2F2|3,1,#F6E7B0|4,1,#F9E083|5,1,#F9E083|6,1,#F9E083|0,2,#F2F2F2|1,2,#F2F2F2|2,2,#F7E5A2|3,2,#F9E083|4,2,#F9E083|5,2,#F9E083|6,2,#F9E083|0,3,#F2F2F2|1,3,#F6E7B0|2,3,#F9E083|3,3,#F9E083|4,3,#F9E083|5,3,#F9E083|6,3,#F9E083|0,4,#F4EED9|1,4,#F9E083|2,4,#F9E083|3,4,#F9E083|4,4,#F9E083|5,4,#F9E083|6,4,#F9E083|0,5,#F6E7B0|1,5,#F9E083|2,5,#F9E083|3,5,#F9E083|4,5,#F9E083|5,5,#F9E083|6,5,#F9E083|0,6,#F8E393|1,6,#F9E083|2,6,#F9E083|3,6,#F9E083|4,6,#F9E083|5,6,#F9E083|6,6,#F9E083', rect=screenshot_coordinates)
    # point = FindColors.find('0,0,#ffffff')

    if point:
        # 打印 x坐标 和 y坐标
        # print(point.x, point.y)

        print(f"get_top_left_coordinates point ：{point.x, point.y}")

        # if point.x == 191:

            # print(f"get_top_left_coordinates point ：{point.x, point.y}")

            # return (point.x, point.y)

        return (point.x, point.y)


def get_top_left_coordinates_list(screenshot_coordinates):


    points = FindColors.find_all('0,0,#F2F2F2|1,0,#F2F2F2|2,0,#F2F2F2|3,0,#F2F2F2|4,0,#F4EED9|5,0,#F6E7B0|6,0,#F8E393|0,1,#F2F2F2|1,1,#F2F2F2|2,1,#F2F2F2|3,1,#F6E7B0|4,1,#F9E083|5,1,#F9E083|6,1,#F9E083|0,2,#F2F2F2|1,2,#F2F2F2|2,2,#F7E5A2|3,2,#F9E083|4,2,#F9E083|5,2,#F9E083|6,2,#F9E083|0,3,#F2F2F2|1,3,#F6E7B0|2,3,#F9E083|3,3,#F9E083|4,3,#F9E083|5,3,#F9E083|6,3,#F9E083|0,4,#F4EED9|1,4,#F9E083|2,4,#F9E083|3,4,#F9E083|4,4,#F9E083|5,4,#F9E083|6,4,#F9E083|0,5,#F6E7B0|1,5,#F9E083|2,5,#F9E083|3,5,#F9E083|4,5,#F9E083|5,5,#F9E083|6,5,#F9E083|0,6,#F8E393|1,6,#F9E083|2,6,#F9E083|3,6,#F9E083|4,6,#F9E083|5,6,#F9E083|6,6,#F9E083', rect=screenshot_coordinates)

    # 分辨率320
    points = FindColors.find_all('0,0,#F1F1F1|1,0,#F1F1F1|2,0,#F1F1F1|3,0,#F1F1F1|4,0,#F1F1F1|5,0,#F2EFE3|6,0,#F6E7AD|7,0,#F9E085|0,1,#F1F1F1|1,1,#F1F1F1|2,1,#F1F1F1|3,1,#F1F1F1|4,1,#F4EBCA|5,1,#F8E087|6,1,#F9E083|7,1,#F9E083|0,2,#F1F1F1|1,2,#F1F1F1|2,2,#F1F1F1|3,2,#F5E9BA|4,2,#F9E083|5,2,#F9E083|6,2,#F9E083|7,2,#F9E083|0,3,#F1F1F1|1,3,#F1F1F1|2,3,#F4ECCC|3,3,#F9E083|4,3,#F9E083|5,3,#F9E083|6,3,#F9E083|7,3,#F9E083|0,4,#F1F1F1|1,4,#F2EFE3|2,4,#F9E187|3,4,#F9E083|4,4,#F9E083|5,4,#F9E083|6,4,#F9E083|7,4,#F9E083|0,5,#F1F1F1|1,5,#F7E6A6|2,5,#F9E083|3,5,#F9E083|4,5,#F9E083|5,5,#F9E083|6,5,#F9E083|7,5,#F9E083|0,6,#F2EFE3|1,6,#F9E083|2,6,#F9E083|3,6,#F9E083|4,6,#F9E083|5,6,#F9E083|6,6,#F9E083|7,6,#F9E083|0,7,#F5E9BC|1,7,#F9E083|2,7,#F9E083|3,7,#F9E083|4,7,#F9E083|5,7,#F9E083|6,7,#F9E083|7,7,#F9E083', rect=screenshot_coordinates)
    # point = FindColors.find('0,0,#ffffff')
    coordinates_list = []
    if points:
        # 打印 x坐标 和 y坐标
        for p in points:
            # print(p.x, p.y)
            coordinates_list.append((p.x, p.y))

    return coordinates_list


# 获取右上角坐标
def get_top_right_coordinates(top_left_coordinates, specific_area):

    # 找到白色结束的地方
    # 如何判断白色结束？
    # 找出该y坐标 轴上所有为#ffffff 的坐标
    # 最后一个就是结束坐标

    # point = FindColors.find('0,0,#f2f2f2', rect=[99, 119, 540, 960])

    # print(specific_area[2])
    # print(top_left_coordinates[1])

    points = FindColors.find_all('0,0,#ffffff', rect=[top_left_coordinates[0], top_left_coordinates[1], specific_area[2], top_left_coordinates[1]+1])

    # print(type(points))

    last_item = None

    if points:
        # 打印 x坐标 和 y坐标
        for p in points:
            last_item = (p.x, p.y)
            # print(p.x, p.y)

    return last_item



# 文字识别
def recognize_text_from_rect(rect):

    # 谷歌OCR 识别中文,并使用自动分割
    # from ascript.android.screen import Ocr
    # res = Ocr.mlkitocr_v2(rect=[rect[0], rect[1], rect[2], rect[3]])

    # 找到屏幕中的所有文字
    # 导包
    from ascript.android.screen import Ocr
    # res = Ocr().paddleocr_v3(rect=[rect[0], rect[1], rect[2], rect[3]])

    res = Ocr().paddleocr_v2(rect=[rect[0], rect[1], rect[2], rect[3]])


    if res:
        # 循环打印识别到的每一个段落
        print(f"识别到行数目：{len(res)}")

        usermassage = ""

        for r in res:
            print("文字:", r.text)
            usermassage = usermassage + r.text.replace("\n", "")
            # print("文字中心坐标:", r.center_x, r.center_y)
            # print("文字范围:", r.rect)

        return usermassage

    return None  # 如果没有识别到文字，返回None


def get_screenshot():

    from ascript.android import screen
    bitmap = screen.capture()

    print(bitmap)

    # 将屏幕截图存储在SD卡下的1.png中
    from ascript.android import screen
    from ascript.android.system import R

    # 获取当前脚本的文件路径
    current_file_path = os.path.abspath(__file__)

    # 获取当前脚本所在的文件夹路径
    current_directory = os.path.dirname(current_file_path)

    current_directory = current_directory.replace("/storage/emulated/0", "", 1)

    print(current_directory)


    screen.bitmap_to_file(R.sd(current_directory + r"/参考2.png"))

# 判断是否接收到新消息
def find_message_redDot():
    find = Selector().id("com.qieyu.bottle:id/conversation_unread").find()
    if find:
        return True

# 判断消息是否为图片
def message_picture_judgment():
    find2 = Selector().id("com.tanyu.me:id/message_num").parent().find()

    if find2.find(Selector().child(3)).__dict__()["text"] == "[图片]":
        logger.info("图片消息回复")

        return True


# 执行图片处理函数
def image_message_processing():


    logger.info("图片消息回复")

    Selector().id("com.tanyu.me:id/message_num").parent().click().find()

    time.sleep(2)
    # logger.info("到了聊天界面")

    # 发送不错
    sendMessage("不错")

    # 退出聊天界面
    Selector().id("com.tanyu.me:id/title_back").click().find()

    time.sleep(1)

def sendMessage(contents):
    logger.info("发送消息给指定人")
    # 点击输入框，输入内容
    Selector().id("com.qieyu.bottle:id/chat_message_input").click().input(contents).find()
    time.sleep(1)

    # 点发送按钮
    Selector().id("com.qieyu.bottle:id/send_btn").click().find()
    time.sleep(1)


# 获取聊天界面用户名
def get_username_from_chat_interface():
    user = Selector().id("com.qieyu.bottle:id/tvNickname").find().text

    return user


# 获取当前界面对方所有消息
def get_all_messages_from_current_view():
    # 320dp
    screenshot_coordinates = [187, 296, 1033, 2106]

    top_left_coordinates_list = get_top_left_coordinates_list(screenshot_coordinates)

    print("top_left_coordinates_list:", top_left_coordinates_list)

    word_rect_list = []

    if top_left_coordinates_list:

        for top_right_coordinates in top_left_coordinates_list:

            bottom_right_coordinates = get_bottom_right_coordinates(top_right_coordinates, screenshot_coordinates)

            if bottom_right_coordinates:
                word_rect_list.append([top_right_coordinates[0], top_right_coordinates[1], bottom_right_coordinates[0],
                                       bottom_right_coordinates[1]])

    print("找到word_rect_list:", word_rect_list)

    recognize_user_message_list = []

    if word_rect_list:

        for word_rect in word_rect_list:

            user_message = recognize_text_from_rect(word_rect)
            if user_message:
                recognize_user_message_list.append(user_message)

    print("recognize_user_message_list:", recognize_user_message_list)

    return recognize_user_message_list



# 获取对方新消息
def get_new_messages_from_user(user, device_id):


    logger.info(f"user ：{user}")
    logger.info(f"device_id ：{device_id}")

    # 先获该用户消息列表
    # 获取当前界面所有消息

    # 未重复的就是新消息

    # 获取当前界面所有信息
    current_interface_all_user_message = get_all_messages_from_current_view()

    # 获取聊天记录
    user_message_list = select_user(user, device_id)


    # 获取聊天记录为空，向云端添加该用户消息，添加一条空消息
    if not user_message_list:
        add_user(user, device_id)








    awaiting_reply_user_message_list = []

    if current_interface_all_user_message:

        for item in current_interface_all_user_message:

            if_item_live = False

            for item2 in user_message_list:

                if item2[1] == item:
                    if_item_live = True
                    break

            if not if_item_live:
                awaiting_reply_user_message_list.append(item)

    return awaiting_reply_user_message_list



def select_user(user, device_id):

    data = {
        'device_id': device_id,
        'user': user,
    }

    # 获取当前脚本的文件路径
    current_file_path = os.path.abspath(__file__)

    # 获取当前脚本所在的文件夹路径
    current_directory = os.path.dirname(current_file_path)

    # 读取 JSON 文件
    with open(current_directory + '/local_config.json', 'r') as file:
        config = json.load(file)
    # 访问配置数据

    url = config["url"]+ "/select_user"

    logger.info(f"select_user url：{url}")

    # url = "http://127.0.0.1:5000/select_user"

    # url = "http://103.149.200.228:8081/select_user"
    response = requests.post(url, json=json.dumps(data))

    # 从回复中 中获取并解析 JSON 数据

    if json.loads(response.text) == "None":
        print("None")
    else:
        user_message_list = json.loads(response.text)
        print(user_message_list)
        return user_message_list



# 获取待回复的消息
def get_awaiting_reply_user_message(user, device_id):


    awaiting_reply_user_message_list = get_new_messages_from_user(user, device_id)

    print(f"awaiting_reply_user_message_list: {awaiting_reply_user_message_list}")

    user_message = ""

    for item in awaiting_reply_user_message_list:
        user_message = user_message + item + "，"

    return user_message



def add_user(user, device_id):


    # 获取原来userlist
    user_message_list = []

    data = {
        'device_id': device_id,
        'user': user,
        'user_message_list': user_message_list,
    }

    massage = []
    massage.append("user")
    massage.append("")
    user_message_list.append(massage)

    # 获取当前脚本的文件路径
    current_file_path = os.path.abspath(__file__)

    # 获取当前脚本所在的文件夹路径
    current_directory = os.path.dirname(current_file_path)

    # 读取 JSON 文件
    with open(current_directory + '/local_config.json', 'r') as file:
        config = json.load(file)
    # 访问配置数据

    url = config["url"] + "/add_user"

    response = requests.post(url, json=json.dumps(data))

    logger.info(f"user添加状态：{response}")
